def i(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True
def s(word_num):
    num_dict = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7',
                'eight': '8', 'nine': '9'}
    num_str = ''.join([num_dict[word] for word in word_num.split()])

    if not num_str.isdigit() or len(num_str) != 3:
        return "Wrong input"
    num = int(num_str)
    a = num
    b = num
    while True:
        if i(a):
            return str(a)
        if i(b):
            return str(b)

        a -= 1
        b += 1
word_num = input()
print(s(word_num))
